package cn.charlab.boot.template;

import cn.charlab.boot.exception.OsException;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;

import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;

public interface StorageTemplate extends InitializingBean, DisposableBean {

    /**
     *
     * @param bucket
     * @return 创建是否成功
     * @throws OsException
     */
    boolean createBucket(String bucket) throws OsException;
    /**
     *
     * @param bucket
     * @return 是否成功
     * @throws OsException
     */
    boolean deleteBucket(String bucket) throws OsException;
    /**
     *
     * @param bucket
     * @return 是否成功
     * @throws OsException
     */
    boolean bucketExists(String bucket) throws OsException;
    /**
     *
     * @param bucket
     * @param key
     * @param input
     * @throws OsException
     */
    void putObject(String bucket, String key, InputStream input)  throws OsException;
    /**
     *
     * @param bucket
     * @param key
     * @param input
     * @param headers
     * @throws OsException
     */
    void putObject(String bucket, String key, InputStream input, Map<String, Object> headers)
            throws OsException;
    /**
     *
     * @param bucket
     * @param key
     * @return 对应的文件流
     * @throws OsException
     */
    InputStream getObject(String bucket, String key) throws OsException;
    /**
     *
     * @param bucket
     * @param key
     * @param out
     * @throws OsException
     */
    void getObject(String bucket, String key, OutputStream out) throws OsException;

    /**
     *
     * @param bucket
     * @param key
     * @return 是否成功
     * @throws OsException
     */
    boolean deleteObject(String bucket, String key) throws OsException;
    /**
     *
     * @param bucket
     * @param key
     * @return 是否成功
     * @throws OsException
     */
    boolean existObject(String bucket, String key) throws OsException;
}
